package com.wg.dome.repository;

import com.wg.dome.entity.user.HeroEntity;
import com.wg.common.lang.HashTable;
import com.wg.db.cache.AbstractMultiCacheRepository;

import java.io.Serializable;
import java.util.HashMap;

public class HeroRepository extends AbstractMultiCacheRepository<HeroEntity> {
    public HeroRepository() {
        super(HeroEntity.class);
    }

    /**
     * 数据转换为hashtable
     */
    public HashTable[] toHashTables(long playerId) {
        HashMap<Serializable, HeroEntity> map = getAllByGroupId(playerId, null);
        HashTable[] hashTables = new HashTable[map.size()];
        int i = 0;
        for (HeroEntity heroEntity : map.values()) {
            hashTables[i++] = heroEntity.toHashTable();
        }
        return hashTables;
    }

    public HeroEntity getEntity(long playerId, byte szPos){
        HeroEntity entity = get(playerId, heroEntity -> heroEntity.getSzPos() == szPos);
        return entity;

    }
}
